package com.todo.common.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.HashUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.todo.common.common.entity.TodoPlatformUserModel;

import java.util.Date;


/**
 * @author zhangwenxiang
 * @date 2024/4/7 17:55
 * @description
 */
public class TodoCommonUtils {

    private static final int workId = 1;
    private static final int dataCenterId = 1;
    private static final Snowflake snowflake = IdUtil.getSnowflake(workId, dataCenterId);

    public static final long DEFAULT_BUCKET_SIZE_100 = 100L;

    public static final String DEFAULT_MEMBER_VIP_ONE_CODE = "LV1";
    public static final String DEFAULT_MEMBER_LEVEL_ONE_CODE = "LV1";


    public static TodoPlatformUserModel getPlatformUserModel() {
        return new TodoPlatformUserModel();
    }

    public static String buildStrGuid() {
        return snowflake.nextIdStr();
    }

    public static Long buildLongGuid() {
        return snowflake.nextId();
    }


    public static Long getBucketByUserId(Long userId, Long bucketSize) {
        return Math.floorMod(userId, bucketSize);
    }


    public static String buildStriHashKey(Long strategyId, Date date) {
        return DigestUtil.md5Hex(strategyId + DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, date));
    }
}
